package org.neuedu.ssmp.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.neuedu.ssmp.crm.entity.OrderList;
import org.neuedu.ssmp.crm.entity.Orders;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: Administrator
 * @Date: 2019/12/18 17:38
 * @Description:
 */
@RestController
@RequestMapping("/oder")
@Slf4j
public class OrdersController {
    @Autowired
    private IOrdersService service;
    @PostMapping("update")
    public ResponseEntity update(@RequestParam String state,@RequestParam Integer id){
        UpdateWrapper<Orders> wrapper = new UpdateWrapper<>();
        wrapper.set("state",state).eq("customer_id",id);
        service.update(wrapper);
        return ResponseEntity.ok("成功");
    }
    @PostMapping("insert")
    public ResponseEntity insert(@RequestBody Orders orders){
        service.save(orders);
        return ResponseEntity.ok("成功");
    }
    @GetMapping("list")
    public Orders list(@RequestParam Integer id){
        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.eq("customer_id",id);
        return service.getOne(wrapper);
    }
    @GetMapping("dindan")
    public IPage<Orders> list(@RequestParam int pageIndex,@RequestParam int pageSize,@RequestParam int customerId){
        return service.ordersPage(pageIndex,pageSize,customerId);
    }
    @GetMapping("dindans")
    public  IPage<OrderList> lists(@RequestParam int pageIndex, @RequestParam int pageSize, @RequestParam int customerId){
        return service.orderDetailPage(pageIndex,pageSize,customerId);
    }
}
